#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main()
{
    pid_t ret = fork();//创建子进程
	while (ret >= 0)//成功创建
	{
        if (ret > 0)//父进程
        {
            pid_t ppid = getppid();//父进程pid
            pid_t pid = getpid();
		    printf("I am pranter; ppid:%d pid:%d\n", ppid, pid);
            sleep(1);  
        }
        else        //子进程
        {

            pid_t ppid = getppid();//父进程pid
            pid_t pid = getpid();
            //不让子进程再次进入外层while循环进行判断
            while (1)
            {
		        printf("I am child; ppid:%d pid:%d\n", ppid, pid);

                sleep(1);  
            }
        }
        sleep(1);  
	}

	return 0;
}
